package com.znsd.zl.house.controller;

import com.znsd.zl.house.entity.RepairEntity;
import com.znsd.zl.house.service.IRepairService;
import com.znsd.zl.utils.BaseController;
import com.znsd.zl.utils.PageUtils;
import com.znsd.zl.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @ClassName RepairController
 * @Description 描述
 * @author zhubin
 * @date 2020-08-21 10:49:21
 * @Version v1.0
 */
@RestController
@RequestMapping("/zl/repair")
@Slf4j
public class RepairController extends BaseController<IRepairService, RepairEntity,Integer> {
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		PageUtils page = service.queryPage(params);
		return R.ok().put("page",page);
	}

	@RequestMapping("/solve")
	public R solve(Integer id){
		service.solve(id);
		return R.ok();
	}

	@GetMapping("/findRepairImage")
	public List<String> findRepairImage(Integer repairId){
		return this.service.findRepairImage(repairId);
	}

	@GetMapping("saveRepair")
	public R saveRepair( RepairEntity repairEntity,@RequestParam List<String> imgList) {
		try {
			return service.saveRepair(repairEntity,imgList) ? R.ok() : R.error("添加失败");
		}catch (Exception e){
			e.printStackTrace();
			return R.error();
		}
	}

	@DeleteMapping
	@Override
	public R deleteBatch(@RequestBody  List<Integer> ids) {
		try {
			log.info("【通用Controller】批量删除成功，删除id：{}", ids);
			this.service.deleteBatch(ids);
		}catch (Exception e){
			e.printStackTrace();
			return R.error("服务器异常，请稍后重试");
		}

		return R.ok();
	}

	/**
	 * 根据维修Id删除图片
	 * @param repairId
	 */
	@RequestMapping("deleteRepairImage")
	public R deleteRepairImage(Integer repairId){

		try {
			service.deleteRepairImage(repairId);
		}catch (Exception e){
			return R.error("服务器异常，请稍后重试");
		}

		return R.ok();
	}


}
